//
//  MeatMeItem.m
//  PigMarket
//
//  Created by 张敬 on 2019/8/3.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "MeatMeItem.h"

@implementation MeatMeItem


- (void)setupUI
{
    [self addSubview:self.icon];
    [self addSubview:self.nameLab];
    [self addSubview:self.tipLab];
    [self addSubview:self.oweLab];

}

- (void)setupLayout
{
    CGFloat number = self.type == MeatMeItemType_Order ?4.0 :3.0;
    CGFloat itemW = (KScreenWidth - 30)/number;
    
    self.width = itemW;
    self.height = 85;
    
    {
        _icon.size = CGSizeMake(24, 24);
        _icon.mj_x = (self.width - _icon.width)/2.0;
        _icon.mj_y = 18;
    }
    
    {
        _nameLab.size = CGSizeMake(itemW, 17);
        _nameLab.mj_x = 0;
        _nameLab.mj_y = _icon.bottom + 8;
    }
    
    {
        _tipLab.size = CGSizeMake(15, 15);
        _tipLab.mj_y = 11;
        _tipLab.mj_x = _icon.right;
    }
    
    {
        _oweLab.size = CGSizeMake(32, 13);
        _oweLab.mj_y = 17;
        _oweLab.mj_x = _icon.right;
    }
    
    if(self.type == MeatMeItemType_Order) _oweLab.hidden = YES;
    if(self.type == MeatMeItemType_Service) _tipLab.hidden =YES;
    
}



- (void)setType:(MeatMeItemType)type{
    
    _type = type;
    [self setupLayout];
}

- (UIImageView *)icon{
    
    if (!_icon) {
        _icon = [UIImageView new];
    }
    return _icon;
}


- (UILabel *)nameLab{
    
    if (!_nameLab) {
        _nameLab = [UILabel makeLabelWithText:@"" textColor:UIColorFromRGB(0x666666) font:mFont(12) textAliment:1];
    }
    return _nameLab;
}

- (UILabel *)tipLab{
    
    if (!_tipLab) {
        _tipLab = [UILabel makeLabelWithText:@"1" textColor:KWhiteColor font:mFont(11) textAliment:1];
        _tipLab.backgroundColor = mMainColor;
        [self addShadowAndCircleCorner:_tipLab.layer corner:7.5];
    }
    return _tipLab;
}

- (UILabel *)oweLab{
    
    if (!_oweLab) {
        _oweLab = [UILabel makeLabelWithText:@"已欠费" textColor:KWhiteColor font:mFont(8) textAliment:1];
        
        UIImage *image = [UIImage imageNamed:@"meat_me_own"];
        UIImageView *bg = [[UIImageView alloc] init];
        bg.image = image;
        bg.frame = CGRectMake(0, -2, 32, 15);
        [_oweLab insertSubview:bg atIndex:0];

    }
    return _oweLab;
}


@end
